<?php
/*
 * Project Name : PaperPlane Server
 * Author       : zbing
 * Date         : 2016/10/13 am 4:15
 * git          : git@git.oschina.net:zbing/paperplane.git
 * framework    : swoole extension
 */
include "./vendor/autoload.php";
class Server {

	//Server Object
	private $Server;

	//server process
	public function __construct($address, $port, $modle=SWOOLE_BASE, $type=SWOOLE_SOCK_TCP, $config='config', $call='call')
	{
		$this->Server = new swoole_server($address, $port, $modle, $type );
		$this->set($config);
		$this->on($call);
		$this->Server->start();
	}

	//server option
	private function set($config)
	{
		$config = include "./app/config/".$config.".php";
		$this->Server->set($config);
	}

	//register callback functions
	private function on($call)
	{
		$calls = include "./app/call/".$call.".php";
		$this->Server->on('connect',['IndexController',$calls['Connect']]);
		$this->Server->on('receive',['IndexController',$calls['Receive']]);
		$this->Server->on('close',['IndexController',$calls['Close']]);
	}

}

$server = new Server('0.0.0.0',9001,SWOOLE_PROCESS,SWOOLE_SOCK_TCP);
